package api

import (
	"api-server/basic/config"
	"api-server/handler/request"
	__ "api-server/proto"
	"context"
	"github.com/gin-gonic/gin"
	"log"
	"net/http"
	"time"
)

func Create(c *gin.Context) {
	var req request.CreateReq
	if err := c.ShouldBind(&req); err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 10000,
			"msg":  "验证失败",
			"date": err.Error(),
		})
		return
	}
	_, cancel := context.WithTimeout(context.Background(), time.Second)
	defer cancel()
	_, err := config.ShopClient.Create(c, &__.CreateReq{
		ShopName: req.ShopName,
		Num:      int64(req.Num),
		Price:    req.Price,
		Details:  req.Details,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "添加成功",
		"date": nil,
	})
}

//func List(c *gin.Context) {
//	var req request.ListReq
//	if err := c.ShouldBind(&req); err != nil {
//		c.JSON(http.StatusOK, gin.H{
//			"code": 10000,
//			"msg":  "验证失败",
//			"date": err.Error(),
//		})
//		return
//	}
//	_, cancel := context.WithTimeout(context.Background(), time.Second)
//	defer cancel()
//	_, err := config.ShopClient.List(c, &__.ListOrderReq{
//		Page:     int64(req.Page),
//		SizePage: int64(req.PageSize),
//	})
//	if err != nil {
//		log.Fatalf("could not greet: %v", err)
//	}
//	var shop model.Shop
//	list := config.DB.First(&shop)
//	c.JSON(http.StatusOK, gin.H{
//		"code": 200,
//		"msg":  "添加成功",
//		"date": list,
//	})
//}
